<template>
	<!-- 供应商列表 -->
	<div>
		<el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>客户列表</el-breadcrumb-item>
		</el-breadcrumb>
		
		<el-form>
			<el-form-item>
				状态：
				<el-switch v-model="showCtrl" active-color="#13ce66" inactive-color="#ff4949">
				</el-switch>
				<div class="sname">
					<span>客户名称</span>
					<el-input style="width:200px;margin-left:10px;" v-model="params.supplierName" />
				</div>
				<el-button @click="getCtrlStatusList" style="float:right;" type="success">搜索</el-button>
			</el-form-item>
		</el-form>
		<el-table border :data="goodsArr" max-width="900">
			<el-table-column width="100" prop="id" label="ID" show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="supplierName" label="供应商名称" show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="supplierChannelNo" label="渠道号">
			</el-table-column>
			<el-table-column prop="supplierState" label="状态">
				<template slot-scope="scope">
					<el-switch v-model="isStatus[scope.$index]" @click.native="ctrlStatus(scope.row.id)" active-color="#13ce66" inactive-color="#ff4949">
					</el-switch>
				</template>
			</el-table-column>
			<el-table-column prop="supplierType" label="类型">
				<template slot-scope="scope">
					<span>{{scope.row.supplierType | filterSupplierType}}</span>
				</template>
			</el-table-column>
			<el-table-column prop="provcity" label="地区">
			</el-table-column>
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button size="small" @click="detail(scope.row.id)" type="success">查看明细</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination class="page-num" background layout="prev, pager, next" :page-size="page_size" @current-change="handleCurrentChange" :total="page">
		</el-pagination>
	</div>
</template>
<script>
	export default {
		name: 'manage',
		data() {
			return {
				title: '',
				goodsArr: [],
				params: {
					"numPerPage": 10,
					"order": "asc",
					"pageNum": 1,
					"supplierStateEnum": "OPEN",
					"supplierName":""
				},
				isStatus: [],
				page_size: 10, //每页显示几个
				page: 0, //总页数
				currentPage: 1, //当前页
				showCtrl:true

			};
		},
		components: {},
		created() {

		},
		mounted() {
			this.getList();
		},

		methods: {
			/*分页跳转*/
			handleCurrentChange: function(currentPage) {
				this.currentPage = currentPage;
				this.getList();
			},
			getCtrlStatusList(){
				this.params.supplierStateEnum = this.showCtrl == true ? 'OPEN' : 'CLOSE';
				this.getList();
				
			},
			// 获取列表
			getList() {
				this.params.pageNum = this.currentPage;
				this.$post("supplierQuery", this.params).then(res => {
					if(res.code == 200) {
						this.goodsArr = [];
						this.page = res.data.total;
						var list = res.data.rows;
						for(var i in list) {
							this.goodsArr.push(list[i]);
							this.isStatus[i] = list[i].supplierState == "OPEN" ? true : false;
						}
					} else {
						this.$msg.warning(res.message);
					}
				});
			},
			// 开启、关闭状态
			ctrlStatus(id) {
				this.$post("supplierControl", { 
					id: id
				}).then(res => {
					if(res.code == 200) {
						this.$msg.success(res.message);
					} else {
						this.$msg.warning(res.message);
					}
				});
			},
			// 跳转详情页面
			detail(id) {
				this.$router.push({
					name: 'updateSupplier',
					params: {
						id: id
					}
				})
			}
		},
	}
</script>
<style type="text/css">
	.sname{
		width:300px;
		display: inline-block;
		margin-left: 30px;
	}
</style>